package swingxrcp.framework.server.environment;

import java.util.Collection;
import java.util.Properties;

import swingxrcp.framework.model.environment.MessageSource;
import swingxrcp.framework.model.environment.Version;
import swingxrcp.framework.util.ConfigUtils;

/**
 * 模块信息
 *
 * @author liangfei
 *
 */
public class Module {

	public static final String DEFAULT_ACTION_SUBPACKAGE_NAME = "action";

	public static final String DEFAULT_SERVICE_SUBPACKAGE_NAME = "service";

	public Module(String name, Properties properties, boolean actionModule) {
		this.configuration = properties;
		this.name = name;
		this.actionModule = actionModule;
		String versionType = properties.getProperty("version.type");
		String versionNumber = properties.getProperty("version.number");
		String releaseDate = properties.getProperty("release.date");
		this.version = new Version(versionNumber, versionType, releaseDate);
		this.packageName = properties.getProperty("package.name");
		this.actionSubpackageName = properties.getProperty("action.subpackage.name", DEFAULT_ACTION_SUBPACKAGE_NAME);
		this.serviceSubpackageName = properties.getProperty("service.subpackage.name", DEFAULT_SERVICE_SUBPACKAGE_NAME);
		this.dependModules = ConfigUtils.split(properties.getProperty("depend.modules"));
		this.messageSource = null; // TODO 国际化信息加载待考虑
	}

	private String name;

	/**
	 * 获取当前模块的名称
	 *
	 * @return 名称
	 */
	public String getName() {
		return name;
	}

	private Version version;

	/**
	 * 获取当前模块的版本
	 *
	 * @return 版本
	 */
	public Version getVersion() {
		return version;
	}

	private String changeLog;

	/**
	 * 获取版本修改日志
	 *
	 * @return 版本修改日志
	 */
	public String getChangeLog() {
		return changeLog;
	}

	private Properties configuration;

	/**
	 * 获取当前模块配置信息
	 *
	 * @return 当前当前模块配置信息
	 */
	public Properties getConfiguration() {
		return configuration;
	}

	private MessageSource messageSource;

	/**
	 * 获取当前模块的国际化信息源
	 *
	 * @return 当前模块的国际化信息源
	 */
	public MessageSource getMessageSource() {
		return messageSource;
	}

	private boolean actionModule;

	/**
	 * 是否为Action模块
	 *
	 * @return 是否为Action模块
	 */
	public boolean isActionModule() {
		return actionModule;
	}

	private String packageName;

	/**
	 * 获取当前模块所需注入的包
	 *
	 * @return 所需注入的包
	 */
	public String getPackageName() {
		return packageName;
	}

	private String actionSubpackageName;

	/**
	 * 获取当前模块所需注入的包
	 *
	 * @return 所需注入的包
	 */
	public String getActionSubpackageName() {
		return actionSubpackageName;
	}

	public String getActionPackageName() {
		return packageName + "." + actionSubpackageName;
	}

	private String serviceSubpackageName;

	/**
	 * 获取当前模块所需注入的包
	 *
	 * @return 所需注入的包
	 */
	public String getServiceSubpackageName() {
		return serviceSubpackageName;
	}

	public String getServicePackageName() {
		return packageName + "." + serviceSubpackageName;
	}

	private Collection<String> dependModules;

	/**
	 * 获取当前模块所依赖的模块
	 *
	 * @return 所依赖的模块
	 */
	public Collection<String> getDependModules() {
		return dependModules;
	}

}
